<?php
    require_once("./classes/sessao.php");
    require_once("./classes/interfaces.php");
    require_once("./classes/conexao.php");

    session_start();

    if (!isset($_SESSION['ANAWEB']))
    {
        $pagina = new Interfaces();
        $pagina->Header(Nao_Logado);
        $pagina->Body();
        echo Nao_Logado_Msg;
        $pagina->Footer();
    }
    else
    {
        //$_SESSION['ANAWEB']->AlteraModo("colaboraabib");
        //$_SESSION['ANAWEB']->AlteraAmbiente("colaborabib");
        $pagina = new Interfaces();
        $pagina->Header(" ANAWEB ");
        $pagina->Body();
?>
        <h1><?php echo Colaborar_Biblioteca ?></h1>
<?php
        $conexao = new Conexao();
        $conexao->Conecta();
?>
        <h2>Bibliotecas que j&aacute; colaboro:</h2>
<?php
        $colaboracoes = $conexao->Executa("SELECT * FROM colaborador_biblioteca WHERE id_user=".$_SESSION['ANAWEB']->RetornaId());
        while ($colaborador = $colaboracoes->FetchRow())
        {
            $biblioteca = $conexao->Executa("SELECT * FROM biblioteca WHERE id_biblioteca=".$colaborador['id_bib']);
            if ($bib = $biblioteca->FetchRow())
            {
?>
        <p><?php echo $bib['NomeBiblioteca']; ?></p>
<?php
            }
        }
?>
        <h2>Esperando autoriza&ccedil;&atilde;o:</h2>
<?php
        $colaboracoes = $conexao->Executa("SELECT * FROM requisicoes_bib WHERE id_user=".$_SESSION['ANAWEB']->RetornaId());
        $bibs = "";
        while ($colaborador = $colaboracoes->FetchRow())
        {
            $bibs = $bibs.$colaborador['id_bib'].",";
            $biblioteca = $conexao->Executa("SELECT * FROM biblioteca WHERE id_biblioteca=".$colaborador['id_bib']);
            if ($bib = $biblioteca->FetchRow())
            {
?>
        <p><?php echo $bib['NomeBiblioteca']; ?></p>
<?php
            }
        }
        $bibs=substr($bibs,0,-1);
?>

        <h2>Pedir para colaborar em:</h2>
        <form action="colaborabiblioteca.php" method="post" name="formcolaborar">
        <select name="biblioteca">
<?php
        $bibinsc = $conexao->Executa("SELECT * FROM biblioteca LEFT JOIN colaborador_biblioteca ON id_biblioteca = colaborador_biblioteca.id_bib AND id_user=".$_SESSION['ANAWEB']->RetornaId()." LEFT JOIN requisicoes_bib ON id_biblioteca=requisicoes_bib.id_bib WHERE colaborador_biblioteca.id_bib IS NULL AND requisicoes_bib.id_bib IS NULL");
        while ($bib = $bibinsc->FetchRow())
        {
?>
            <option value="<?php echo $bib['id_biblioteca']?>"><?php echo $bib['NomeBiblioteca'] ?></option>
<?php
        }
?>
        </select>
        <input type="submit" name="enviar" value="Pedir">
        </form>
<?php
        $pagina->Footer();
    }
?>
